<template>
  <div>
    <div id="chart" style="width: 100%; height: 470px"></div>
  </div>
</template>
  <script>
export default {
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.$store.dispatch("data-analysis/product", {}).then((res) => {
        this.list = res.data.map(item => {
          return { name: item.product, value: item.count }
        });
        this.initChart();
      });
    },
    initChart() {
      var ele = document.getElementById("chart");
      var chart = this.echarts.init(ele);
      var option = {
        title: {
          text: "耗材使用量分析",
          subtext: "近一个月内使用量前十的耗材信息",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            name: "使用量",
            type: "pie",
            radius: "60%",
            center:"center",
            data: this.list,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      chart.setOption(option);
    },
  },
};
</script>